import requests
import json
from faker import Faker
import random
import time
from datetime import datetime, timedelta

fake = Faker()

def generate_wearable_data():
    return {
        "deviceId": fake.uuid4(),
        "heartRate": random.randint(60, 100),
        "steps": random.randint(0, 1000),
        "sleepDuration": round(random.uniform(0, 8), 2),
        "timestamp": datetime.now().isoformat()
    }

def send_data():
    url = "http://localhost:8080/api/wearable/data"
    headers = {"Content-Type": "application/json"}
    
    while True:
        data = generate_wearable_data()
        try:
            response = requests.post(url, json=data, headers=headers)
            print(f"Data sent: {data}")
            print(f"Response: {response.status_code}")
        except Exception as e:
            print(f"Error sending data: {e}")
        
        time.sleep(5)  # 每5秒发送一次数据

if __name__ == "__main__":
    send_data() 